import {defineStore} from 'pinia'
import website from "@/config/website";

const tagWel = website.fistPage;


export default    defineStore('routerStore', {
    state: () => {
        return {
            tagList: [],
            tag: {},
            tagWel: tagWel
        }
    },
    getters:{
        tagsKeep: (state) => {
            return state.tagList.filter(ele => {
                return (ele.meta || {}).keepAlive
            }).map(ele => ele.fullPath)
        },
    },
    actions: {
        addTag(action) {
            if (typeof action.name == 'function') action.name = action.name(action.query)
            this.tag = action;
            if (this.tagList.some(ele => ele.fullPath === action.fullPath)) return
            this.tagList.push(action)
        },
        delTag(action) {
            this.tagList = this.tagList.filter(item => {
                return item.fullPath !== action.fullPath
            })
        },
        delAllTag(tagList = []) {
            this.tagList = tagList
        },
        delOtherTag() {
            this.tagList = this.tagList.filter(item => {
                return [this.tag.fullPath, website.fistPage.path].includes(item.fullPath)
            })
        }
    },
    persist: true
})
